<?php
/**
 *
 * @author Tongle Xu <xutongle@gmail.com> 2013-11-18
 * @copyright Copyright (c) 2003-2103 tintsoft.com
 * @license http://www.tintsoft.com
 * @version $Id$
 */
namespace Leaps\Cache\Adapter;
use Leaps\Cache\Section;
use Leaps\Cache\AdapterInterface;
class WinCache implements AdapterInterface
{

    /**
     * Create a new WinCache store.
     *
     * @param string $prefix
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * (non-PHPdoc)
     *
     * @see \Leaps\Cache\StoreInterface::get()
     */
    public function get($key)
    {
        $value = wincache_ucache_get ( $key );
        if ( $value !== false ) {
            return $value;
        }
    }

    /**
     * (non-PHPdoc)
     *
     * @see \Leaps\Cache\StoreInterface::set()
     */
    public function set($key, $value, $minutes)
    {
        wincache_ucache_add ( $this->prefix . $key, $value, $minutes * 60 );
    }

    /**
     * (non-PHPdoc)
     *
     * @see \Leaps\Cache\StoreInterface::forever()
     */
    public function forever($key, $value)
    {
        return $this->set ( $key, $value, 0 );
    }

    /**
     * (non-PHPdoc)
     *
     * @see \Leaps\Cache\StoreInterface::delete()
     */
    public function delete($key)
    {
        wincache_ucache_delete ( $this->prefix . $key );
    }

    /**
     * (non-PHPdoc)
     *
     * @see \Leaps\Cache\StoreInterface::flush()
     */
    public function flush()
    {
        wincache_ucache_clear ();
    }

    /**
     * Begin executing a new section operation.
     *
     * @param string $name
     * @return \Leaps\Cache\Section
     */
    public function section($name)
    {
        return new Section ( $this, $name );
    }
}